package day10_xml;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/*
请定义xml文件，存储以下“图书”信息：
*/
public class WriteXML {
//1. 使用：文档声明
//2. “标签名”不可使用中文。
//3. 文件名为：books.xml
//4. 根元素为：\<books>

    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
        sb.append("<books>\r\n");
        sb.append("\t<book>\r\n");
        sb.append("\t\t<name>").append("架构师成长之路").append("</name>\r\n");
        sb.append("\t\t<publisher>").append("黑马程序员").append("</publisher>\r\n");
        sb.append("\t\t<date>").append("2010-6-6").append("</date>\r\n");
        sb.append("\t\t<price>").append("125.00").append("</price>\r\n");
        sb.append("\t</book>\r\n");
        sb.append("\t<book>\r\n");
        sb.append("\t\t<name>").append("JaveEE企业级开发").append("</name>\r\n");
        sb.append("\t\t<publisher>").append("黑马研究院").append("</publisher>\r\n");
        sb.append("\t\t<date>").append("2011-5-5").append("</date>\r\n");
        sb.append("\t\t<price>").append("115.80").append("</price>\r\n");
        sb.append("\t</book>\r\n");
        sb.append("\t<book>\r\n");
        sb.append("\t\t<name>").append("Oracle指南").append("</name>\r\n");
        sb.append("\t\t<publisher>").append("清华计算机").append("</publisher>\r\n");
        sb.append("\t\t<date>").append("2012-7-7").append("</date>\r\n");
        sb.append("\t\t<price>").append("89.00").append("</price>\r\n");
        sb.append("\t</book>\r\n");
        sb.append("</books>");
        System.out.println(sb.toString());

        try (BufferedWriter bw = new BufferedWriter(new FileWriter("src/books.xml"));){

            bw.write(sb.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
